Jupyter at Bryn Mawr College |
|||
Public notebooks: /services/public/dblank / Experiments |
import java.util.*;
int n = 12;
int p = 0, c = 1, a;
List<Integer> list = new ArrayList<>();
while (n-- > 0) {
list.add(c);
a = p + c;
p = c;
c = a;
}
System.out.println(list);
int var1 = 2
int meth2() {
return var1+2;
}
++var1
class class3 {
int meth4() {
return var1 * meth2();
}
}
System.out.println(new class3().meth4())
int passCnt
int failCnt
int unexpectedCnt
void check(boolean pass) {
if (pass) {
System.out.println("pass");
++passCnt;
} else {
System.out.println("FAIL");
++failCnt;
}
}
void expectError(boolean huh) {
System.out.println("Should not be here, should be error");
++unexpectedCnt;
}
int m() { return 100; }
int m(int x) { return x; }
int m(int x, int y) { return x * y; }
check(m(5,4) == 20);
check(m(7) == 7);
check(m() == 100);
int m(int x) { return x * 100; }
check(m(3) == 300);
check(m() == 100);
check(m(5,4) == 20);
int m() { return 1234; }
check(m() == 1234);
double m(int x, int y) { return x + y; }
check(m(2,3) == 5.0);
double m(double x, double y) { return y - x; }
check(m(2.0,3.0) == 1.0);
check(m(2,3) == 5.0);
System.out.println((passCnt==10 && failCnt==0 && unexpectedCnt==0)?
"Test passes!" :
"Test FAILED! Pass: " + passCnt + ", Fail: " + failCnt + ", Unexpected: " + unexpectedCnt)
int passCnt;
int failCnt;
int unexpectedCnt;
/*
void check(boolean pass) {
if (pass) {
System.out.println("pass");
++passCnt;
} else {
System.out.println("FAIL");
++failCnt;
}
}
*/
/*
void expectError(boolean huh) {
System.out.println("Should not be here, should be error");
++unexpectedCnt;
}
*/
int x;
//int mu() { return x * 4; }
//class C {
// String v() { return "#" + mu(); }
//}
//new C();
//check($1.v().equals("#0"))
/*
int x = 10
check($1.v().equals("#40"))
C c = new C()
check(c.v().equals("#40"))
int mu() { return x * 3; }
check(c.v().equals("#30"))
class C {
String v() { return "@@" + mu(); }
}
check($1.v().equals("@@30"))
c = new C()
check(c.v().equals("@@30"))
double x = 2.5
check(x == 2.5)
*/
/*
expectError(mu() == 30)
c = new C()
expectError(c.v().equals("@@30"))
int mu() { return (int) (x * 10); }
check(mu() == 25)
c = new C()
check(c.v().equals("@@25"))
double mu() { return x * 2.0; }
check(mu() == 5.0)
check($1.v().equals("@@5.0"))
c = new C()
check(c.v().equals("@@5.0"))
class C {
Object v() { return mu(); }
}
//check($1 == null) //TODO fix update of temp vars
C d = new C()
check(d.v().equals(5.0))
System.out.println((passCnt==13 && failCnt==0 && unexpectedCnt==0)?
"Test passes!" :
"Test FAILED! Pass: " + passCnt + ", Fail: " + failCnt + ", Unexpected: " + unexpectedCnt)
*/
System.out.println("Ok")
System.out.println("Ok")
class Tree {
Tree left;
Tree right;
int value;
Tree(int value) {
this.value = value;
}
}
Tree tree = new Tree(10);
tree.left = new Tree(2);
tree.left.value
$2
System.out.println(y)
System.out.println(1/0)
System.out.println("ok")
%%python
kernel.javawrapper.child.send("varia")
kernel.javawrapper.child.sendcontrol('t')
kernel.javawrapper.child.sendeof()
System.out.println("ok")
/help
/help
/help
%%python
kernel.javawrapper.child.read(10)
int variable_name = 1;
variable_name
variable_name
variable_name
variable_name